<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计数器</title>
    <link rel="stylesheet" href="css/counter.css">
</head>
<body>
    <div id="vm">
        <div class="layer">
            <button @click="count(-1)" class="btn">-</button>
            <div class="box" v-text="num"></div>
            <button @click="count(1)" class="btn">+</button>
        </div>
    </div>
    <script src="js/vue.js"></script>
    <script>
        var vm = new Vue({
            el:"#vm",
            data:{
                num:0
            },
            methods:{
                count(val){
                    var rs = this.num + val;
                    this.num = rs < 0 ? 0 : rs; 
                }
            }
        })
    </script>
</body>
</html>